from welcome . logic import welcome_logic

class mediator_fake :
    def __init__ ( self ) :
        self . _welcome_finished = False
    def on_welcome_finished ( self ) :
        self . _welcome_finished = True

class welcome_logic_tests :
    'welcome_logic'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _welcome_logic = welcome_logic ( self . _mediator )
    def test_show_welcome ( self ) :
        self . _test . assume_equal ( self . _welcome_logic . show_welcome ( ) , None )
    def test_hide_welcome ( self ) :
        self . _test . assume_equal ( self . _welcome_logic . hide_welcome ( ) , None )
        
    #
    # on_mouse_button_1
    #
        
    def test_send_welcome_finished_after_mouse_button_1_click ( self ) :
        self . _check_welcome_finished_after_show_welcome ( 'on_mouse_button_1' )
    def test_dont_send_welcome_finished_after_mouse_button_1_click_before_show_welcome ( self ) :
        self . _check_welcome_finished_before_show_welcome ( 'on_mouse_button_1' )
    def test_dont_send_welcome_finished_after_mouse_button_1_click_after_hide_welcome ( self ) :
        self . _check_welcome_finished_after_hide_welcome ( 'on_mouse_button_1' )
        
    #
    # on_any_key
    #
        
    def test_send_welcome_finished_after_any_key_pressed ( self ) :
        self . _check_welcome_finished_after_show_welcome ( 'on_any_key' )
    def test_dont_send_welcome_finished_after_any_key_pressed_before_show_welcome ( self ) :
        self . _check_welcome_finished_before_show_welcome ( 'on_any_key' )
    def test_dont_send_welcome_finished_after_any_key_pressed_after_hide_welcome ( self ) :
        self . _check_welcome_finished_after_hide_welcome ( 'on_any_key' )

    #
    # on_key_up
    #

    def test_send_welcome_finished_after_key_up_pressed ( self ) :
        self . _check_welcome_finished_after_show_welcome ( 'on_key_up' )
    def test_dont_send_welcome_finished_after_key_up_pressed_before_show_welcome ( self ) :
        self . _check_welcome_finished_before_show_welcome ( 'on_key_up' )
    def test_dont_send_welcome_finished_after_key_up_pressed_after_hide_welcome ( self ) :
        self . _check_welcome_finished_after_hide_welcome ( 'on_key_up' )

    #
    # on_key_down
    #

    def test_send_welcome_finished_after_key_down_pressed ( self ) :
        self . _check_welcome_finished_after_show_welcome ( 'on_key_down' )
    def test_dont_send_welcome_finished_after_key_down_pressed_before_show_welcome ( self ) :
        self . _check_welcome_finished_before_show_welcome ( 'on_key_down' )
    def test_dont_send_welcome_finished_after_key_down_pressed_after_hide_welcome ( self ) :
        self . _check_welcome_finished_after_hide_welcome ( 'on_key_down' )

    #
    # on_key_return
    #

    def test_send_welcome_finished_after_key_return_pressed ( self ) :
        self . _check_welcome_finished_after_show_welcome ( 'on_key_return' )
    def test_dont_send_welcome_finished_after_key_return_pressed_before_show_welcome ( self ) :
        self . _check_welcome_finished_before_show_welcome ( 'on_key_return' )
    def test_dont_send_welcome_finished_after_key_return_pressed_after_hide_welcome ( self ) :
        self . _check_welcome_finished_after_hide_welcome ( 'on_key_return' )

    #
    # on_key_escape
    #

    def test_send_welcome_finished_after_key_escape_pressed ( self ) :
        self . _check_welcome_finished_after_show_welcome ( 'on_key_escape' )
    def test_dont_send_welcome_finished_after_key_escape_pressed_before_show_welcome ( self ) :
        self . _check_welcome_finished_before_show_welcome ( 'on_key_escape' )
    def test_dont_send_welcome_finished_after_key_escape_pressed_after_hide_welcome ( self ) :
        self . _check_welcome_finished_after_hide_welcome ( 'on_key_escape' )

    #
    # welcome_finished helpers
    #
    
    def _check_welcome_finished_after_show_welcome ( self , event_name ) :
        self . _welcome_logic . show_welcome ( )
        getattr ( self . _welcome_logic , event_name ) ( )
        self . _test . assume_true ( self . _mediator . _welcome_finished )
    def _check_welcome_finished_before_show_welcome ( self , event_name ) :
        getattr ( self . _welcome_logic , event_name ) ( )
        self . _welcome_logic . show_welcome ( )
        self . _test . assume_false ( self . _mediator . _welcome_finished )
    def _check_welcome_finished_after_hide_welcome ( self , event_name ) :
        self . _welcome_logic . show_welcome ( )
        self . _welcome_logic . hide_welcome ( )
        getattr ( self . _welcome_logic , event_name ) ( )
        self . _test . assume_false ( self . _mediator . _welcome_finished )
